//
//  AuthenRemarkVM.swift
//  kxf
//  进件 备注
//  Created by Mac on 2024/3/6.
//

import Foundation
import UIKit

class AuthenRemarkVM: UIView {
    
    let selfHeight = RegisterInputVM().selfHeight*2

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var lineView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LINE_GREY
        
        return vi
    }()
    lazy var titleLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 14, weight: .medium)
        lab.text = "备注"
        return lab
    }()
    lazy var textView : UITextView = {
        let vi = UITextView()
//        vi.text = "如：XX网络科技公司,需备注（收取技术服务费）"
        vi.font = .systemFont(ofSize: 15, weight: .regular)
        vi.delegate = self
        
        return vi
    }()
    lazy var placeHolderLabel : UILabel = {
        let lab = UILabel()
        lab.text = "如：XX网络科技公司,需备注（收取技术服务费）"
        lab.textColor = .COLOR_TEXT_BLACK999
        lab.font = .systemFont(ofSize: 15, weight: .regular)
        lab.numberOfLines = 0
        lab.lineBreakMode = .byCharWrapping
        
        return lab
    }()
}

extension AuthenRemarkVM{
    func initUI() {
        addSubview(lineView)
        addSubview(titleLabel)
        addSubview(textView)
        addSubview(placeHolderLabel)
        
        setConstrait()
    }
    func setConstrait() {
        lineView.snp.makeConstraints { make in
            make.left.width.top.equalToSuperview()
            make.height.equalTo(kFitWidth(0.3))
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(24))
            make.top.equalTo(kFitWidth(22))
        }
        textView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(121))
            make.top.equalTo(kFitWidth(15))
            make.right.equalTo(kFitWidth(-20))
            make.bottom.equalTo(kFitWidth(-20))
        }
        placeHolderLabel.snp.makeConstraints { make in
            make.left.right.equalTo(textView)
//            make.height.equalTo(kFitWidth(60))
            make.top.equalTo(titleLabel)
        }
    }
}

extension AuthenRemarkVM:UITextViewDelegate{
    func textViewDidBeginEditing(_ textView: UITextView) {
        self.placeHolderLabel.isHidden = true
    }
    func textViewDidEndEditing(_ textView: UITextView) {
        if textView.text.count > 0 {
            self.placeHolderLabel.isHidden = true
        }else{
            self.placeHolderLabel.isHidden = false
        }
    }
}
